#include<iostream>
#include <ostream>
using namespace std;
class Date{
    
public:
    
    friend ostream& operator<<(ostream& out,const Date&d);
    friend istream& operator>>(istream& in, Date&d);
   
    Date(int day=1,int month=1,int year=1)
    {
        if(month>0&&month<13&&day>0&&day<getmonth(year,month))
            _day=day,_month=month,_year=year;
        else
            cout<<"输入错误";
    }

    Date(const Date&d)
    {
        _day=d._day;
        _month=d._month;
        _year=d._year;
        cout<<"copy"<<endl;
    }

    int getmonth(int year,int month)
    {
        static int monthday[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
        if((year%4==0&&year%100!=0)||year%400==0)
        {
            if(month==2)return 29;
        }
        return monthday[month];
    }

    void print()
    {
        cout<<"day: "<<_day<<" month: "<<_month<<" year: "<<_year<<endl;
    }


    Date operator=(const Date d)
    {
        _day=d._day;
        _month=d._month;
        _year=d._year;
        return *this;
    }


    Date& operator+=(int Day)
    {
        if(Day<0)
        {
            *this-=(-Day);
            return *this;
        }
        _day+=Day;
        while(_day>getmonth(_year,_month))
        {
            _day-=getmonth(_year,_month);
            ++_month;
            if(_month>12)
            {
                _month=1;
                _year++;
            }
        }
        return *this;
    }
    Date operator+(int day)
    {
        Date tmp=*this;
        tmp+=day;
        tmp.print();
        return tmp;
    }
    Date& operator++()
    {
        *this+=1;
        return *this;
    }
    Date operator++(int)
    {
        Date tmp=*this;
        *this+=1;
        return tmp;
    }

    int operator-(Date &d)
    {
        Date max=*this;
        Date min=d;
        int flag=1;
        if(max<min)
        {
            max=d;
            min=*this;
            flag=-1;
        }
        int n=0;
        while(min!=max)
        {
            ++min;
            ++n;
        }
        return n*flag;
    }
    
    Date& operator-=(const int Day)
    {
        if(Day<0)
        {
            *this+=(-Day);
            return *this;
        }
        _day-=Day;
        while(_day<=0)
        {
            --_month;
            if(_month<1)
            {
                _year--;
                _month=12;
            }
            _day+=getmonth(_year,_month);
        }
        return *this;
    }
    
    Date operator-(const int Day)
    {
        Date tmp=*this;
        return tmp-=Day;
    }

    Date& operator--()
    {
        *this-=1;
        return *this;
    }

    Date operator--(int)
    {
        Date tmp;
        *this-=1;
        return tmp;
    }



    bool operator==(const Date&d)const
    {
        if(_year==d._year&&_month==d._month&&_day==d._day)
        {
            return true;
        }
        return false;
    }
    bool operator!=(const Date&d)const
    {
        if(*this==d)return false;
        return true;
    }
    bool operator<(const Date &d)const
    {
        if(_year<d._year)
        {
            return true;
        }
        if(_year==d._year&&_month<d._month)
        {
            return true;
        }
        if(_year==d._year&&_month==d._month&&_day<d._day)
        {
            return true;
        }
        return false;  
    }

    bool operator<=(const Date &d)const
    {
        return *this<d||*this==d;
    }

    bool operator>(const Date &d)const
    {
        return (!(*this<d)&&(*this!=d))?true:false;
    }
    bool operator>=(const Date &d)const
    {
        return !(*this<d);
    }


private:
    int _year;
    int _month;
    int _day;
};

ostream& operator<<(ostream& out,const Date&d)
{
   out<<"day: "<<d._day<<" month: "<<d._month<<" year: "<<d._year<<endl;
   return out;
}

istream& operator>>(istream& in,Date&d)
{
   	int year, month, day;
	in >> day >> month >>year;

	if (month > 0 && month < 13
		&& day > 0 && day <= d.getmonth(year, month))
	{
		d._year = year;
		d._month = month;
		d._day = day;
	}
	else
	{
		cout << "非法日期" << endl;
	}
	return in;
}

int main()
{
     
    Date d1(2,5,2024);
    d1+=100;
    d1.print();
}